<?php
// Change logs
//  Sep 9, 2011 - trungdt - Add aggregate
// 5/8/2010: Immanuel192 write this modeller

class documentsmodule_document {
	function form($object,$config) {
		global $db;
		
		if (!defined('SYS_FORMS')) require_once(BASE.'subsystems/forms.php');
		exponent_forms_initialize();

		$form = new form();
        
        $lang= exponent_lang_loadFile('datatypes/documentsmodule_document.php');
		if (!isset($object->id)) {
			$object->name="";
			$object->author = '';
			$object->download = 0;
			$object->date=time();
			
            $object->mp3_filetype=0; // =0: select file on system; =1: url
            $object->mp3_file=-1;
            $object->mp3_url="";
            
            $object->doc_filetype=0; // =0: select file on system; =1: url
            $object->doc_file=-1;
            $object->doc_url="";
            
            $object->ppt_filetype=0; // =0: select file on system; =1: url
            $object->ppt_file=-1;
            $object->ppt_url="";
            
            $object->pdf_filetype=0; // =0: select file on system; =1: url
            $object->pdf_file=-1;
            $object->pdf_url="";
            
            $object->xls_filetype=0; // =0: select file on system; =1: url
            $object->xls_file=-1;
            $object->xls_url="";
            
            
            $object->ppt_file=-1;
			$object->pdf_file=-1;$object->doc_file=-1;
            $object->series_name = '';
		} else {
			$form->meta('id',$object->id);
		}
		
		// get all current pastors in this module for combobox
		$pastors_temp=$db->selectDropdown("documentsmodule_document","author","location_data = '{$config->location_data}' GROUP BY author");
		$pastors=array();
		$pastors['no_selected']=$lang['add_new'];
        $pastor_default = "no_selected";
		foreach ($pastors_temp as $k=>$v)
		{
            if (trim($v)!="")
            {
                $pastors[$v]=$v;
            }
            if ($object->author == $v)
                $pastor_default = $v;
        }
		$form->register('name',$lang['name'],new textcontrol($object->name));
		
        $form->register('author_dropdown',$lang['author'],new dropdowncontrol($pastor_default,$pastors));
        $form->register(null,'',new htmlcontrol($lang['selectnamenotify']));
		$form->register('author','',new textcontrol(""));
        
        // Sept 23, 2010: trungdt - Add sermon series - begin
        $series_temp=$db->selectDropdown("documentsmodule_document","series_name","location_data = '{$config->location_data}' GROUP BY series_name");
        $series=array();
        $series['no_selected']=$lang['add_new'];
        $series_default = "no_selected";
        foreach ($series_temp as $k=>$v)
        {
            if (trim($v)!="")
            {
                $series[$v]=$v;      
            }
            if ($object->series_name == $v)
                $series_default= $v;
        }
        $form->register('series_dropdown',$lang['series'],new dropdowncontrol($series_default,$series));
        $form->register(null,'',new htmlcontrol($lang['selectseriesnotify']));
        $form->register('series_name','',new textcontrol(""));
        // Sept 23, 2010: trungdt - Add sermon series - end
		
		$form->register('date',$lang['date'],new datetimecontrol($object->date, true, false));
        
        $form->register('xls_file',$lang['excelfile'], new ajax_select_file("xls_file",$config->xls_col,$object->xls_file,true));

		$form->register('mp3_file',$lang['mp3file'], new ajax_select_file("mp3_file",$config->mp3_col,$object->mp3_file,true));
        $form->register(null,'',new htmlcontrol("<br>"));
		$form->register('doc_file',$lang['docfile'], new ajax_select_file("doc_file",$config->doc_col,$object->doc_file,false));
        $form->register(null,'',new htmlcontrol("<br>"));
		$form->register('pdf_file',$lang['pdffile'], new ajax_select_file("pdf_file",$config->pdf_col,$object->pdf_file,false));
        $form->register(null,'',new htmlcontrol("<br>"));
		$form->register('ppt_file',$lang['pptfile'], new ajax_select_file("ppt_file",$config->ppt_col,$object->ppt_file,false));
        $form->register(null,'',new htmlcontrol("<br>"));
		$form->register('submit','',new buttongroupcontrol($lang['save'],'','Cancel'));
		return $form;
	}

	function update($values,$object) {
		$object->name = $values['name'];
		// for pastor name
		$object->author=$values['author'];
		if (!($values['author_dropdown']=='no_selected'))
			$object->author=$values['author_dropdown'];
            
        // Sept 23, 2010: trungdt - Add sermon series - begin
        // for pastor name
        $object->series_name=$values['series_name'];
        if (!($values['series_dropdown']=='no_selected'))
            $object->series_name=$values['series_dropdown'];
        // Sept 23, 2010: trungdt - Add sermon series - begin
        
		$object->date=mktime(0,0,0,$values['date_month'],$values['date_day'],$values['date_year']);
        $object->xls_file = $values['xls_file'];
		$object->mp3_file = $values['mp3_file'];
		$object->doc_file = $values['doc_file'];
		$object->pdf_file = $values['pdf_file'];
		$object->ppt_file = $values['ppt_file'];
		return $object;
	}
}

?>
